package com.yunhai.xc.user.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.yunhai.xc.user.domain.User;
import com.yunhai.xc.user.persistence.UserMapper;

@Service
public class UserService {
	@Autowired
	private UserMapper userMapper;

	public User selectByUserName(String username) {
		return userMapper.selectByUserName(username);
	}

	@Cacheable(value = "data", key = "'user:'+#user.id")
	public User selectById(Integer id) {
		return userMapper.selectById(id);
	}

	@CachePut(value = "data", key = "'user:'+#p0") // 修改
	public User updateById(Integer id) {
		userMapper.updateById(id);
		User u = userMapper.selectById(id);
		return u;
	}

	@CacheEvict(value = "data", key = "'user:'+#p0") // 删除
	public void deleteById(Integer id) {
		userMapper.deleteById(id);
	}

}
